<template>
  <view
    class="news-detail bg-white px-5.25 py-3 box-border min-h-[100vh] flex flex-col"
  >
    <text class="text-[29rpx] text-black">{{ deatilInfo.title }}</text>
    <text class="text-[25rpx] text-[#8A8A8A] mt-2.5"
      >发布时间：
      {{
        deatilInfo.createTime
          ? dayjs(deatilInfo.createTime).format("YYYY-MM-DD hh:mm:ss")
          : ""
      }}</text
    >
    <up-divider lineColor="#BBBBBB"></up-divider>
    <view class="news-content">
      <template v-if="deatilInfo.videoUrl">
        <video
          controls
          :src="encodeURI(imgPrefix + deatilInfo.videoUrl)"
          style="width: 100%; height: 400rpx; margin-bottom: 30rpx"
        />
      </template>
      <!-- <rich-text :nodes="deatilInfo.fwb"></rich-text> -->
      <!-- <rich-text class="fuwenb" :nodes="deatilInfo.content"></rich-text> -->
      <mp-html :content="deatilInfo.content" />
    </view>
    <up-toast ref="uToastRef"></up-toast>
  </view>
</template>

<script setup lang="ts">
import mpHtml from 'mp-html/dist/uni-app/components/mp-html/mp-html'
import {
  detailAntiFraud,
  detailFireSafety,
  detailPreventiveTip,
  regulationsselectOne,
  integrityselectOne,
} from "@/api/news/index";
import { imgPrefix } from "@/config/app";
import dayjs from "dayjs";

const uToastRef = <any>ref(null);
const request = ref([
  detailAntiFraud,
  detailFireSafety,
  detailPreventiveTip,
  regulationsselectOne,
  integrityselectOne,
  integrityselectOne,
]);
const deatilInfo = <any>ref({});

onLoad((options) => {
  if (options) {
    initNewsDetail(options.newsId, options.newsType);
  }
});

// 获取对应的新闻详情
const initNewsDetail = (id: number, type: number) => {
  uni.showLoading({
    title: "加载中",
    mask: true,
  });

  // if (type == 4 || type == 5) {
  //   integrityselectOne({ id, type: "crowd" })
  //     .then((res: any) => {
  //       uni.hideLoading();
  //       const { data } = res;
  //       deatilInfo.value = data;
  //     })
  //     .catch((err: any) => {
  //       uni.hideLoading();
  //       uToastRef.value.show({
  //         type: "error",
  //         message: err,
  //       });
  //     });
  // }
  // } else {
  request.value[type]({ id, type: "crowd" })
    .then((res: any) => {
      uni.hideLoading();
      const { data } = res;
      // let fwb = data.content.replace(
      //   /<img/gi,
      //   '<img style="max-width:100%;height:auto;display:block;"'
      // );
      // console.log(fwb);
      // data.fwb = fwb;
      deatilInfo.value = data;
    })
    .catch((err: any) => {
      uni.hideLoading();
      uToastRef.value.show({
        type: "error",
        message: err,
      });
    });
  // }
};
</script>

<style lang="scss" scoped>
</style>
